package com.cskaoyan.shopping.controller;

import com.cskaoyan.mall.commons.result.ResponseData;
import com.cskaoyan.mall.commons.result.ResponseUtil;
import com.cskaoyan.mall.dto.ProductDetailDto;
import com.cskaoyan.shopping.dto.AllProductResponse;
import com.cskaoyan.shopping.dto.TestProductDetailDto;
import com.cskaoyan.shopping.form.PageRequest;
import com.cskaoyan.shopping.service.IProductService;
import com.cskaoyan.shopping.service.ITestProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;

@RestController
public class TestProductController {

    @Autowired
    ITestProductService productService;



    @Autowired
    IProductService iProductService;




    @GetMapping("/shopping/product/{id}")
    public ResponseData getProductDetailById(@PathVariable("id") Long id){
        ProductDetailDto productDetail = iProductService.getProductDetail(id);
        return new ResponseUtil().setData(productDetail);
    }

    @GetMapping("/shopping/goods")
    public ResponseData getAllGood(PageRequest pageRequest){
        AllProductResponse allProduct = iProductService.getAllProduct(pageRequest);
        ResponseData responseData = new ResponseUtil().setData(allProduct);
        return responseData;
    }

    /**
     * zxy,仅用于练习教师课堂示例，测试用，http://localhost:8080/shopping/test?productId=1000235010
     * @param productId
     * @return
     */
    @GetMapping("/shopping/test")
    public ResponseData getProductDetail(@NotNull Long productId) {
        TestProductDetailDto productDetail = productService.getProductDetail(productId);// test的service，非productService
        return new ResponseUtil().setData(productDetail);
    }

}
